package com.lovo.user.mq;

import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class DeadLetterReceiver {
    @RabbitListener(queues = {"dead.letter.queue"})
    public void receive(String content, Message message, Channel channel){
        System.out.println("进入死信队列："+content);
        try {
            // 确认消息被消费
            channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
